package com.cxhc.system.service.app.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.cxhc.common.utils.DateUtils;
import com.cxhc.system.domain.app.CmRoomInfo;
import com.cxhc.system.mapper.app.CmRoomInfoMapper;
import com.cxhc.system.service.app.ICmRoomInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 房间信息Service业务层处理
 * 
 * @author Dhq
 * @date 2024-11-14
 */
@Service
public class CmRoomInfoServiceImpl implements ICmRoomInfoService
{
    @Autowired
    private CmRoomInfoMapper cmRoomInfoMapper;

    /**
     * 查询房间信息
     * 
     * @param id 房间信息主键
     * @return 房间信息
     */
    @Override
    public CmRoomInfo selectCmRoomInfoById(Long id)
    {
        return cmRoomInfoMapper.selectCmRoomInfoById(id);
    }

    /**
     * 查询房间信息列表
     * 
     * @param cmRoomInfo 房间信息
     * @return 房间信息
     */
    @Override
    public Map<String, List<CmRoomInfo>> selectCmRoomInfoList(CmRoomInfo cmRoomInfo)
    {
        List<CmRoomInfo> cmRoomInfos = cmRoomInfoMapper.selectCmRoomInfoListAndHouseholdInfo(cmRoomInfo);
        return cmRoomInfos.stream().collect(Collectors.groupingBy(CmRoomInfo::getRoomFloor));
    }

    /**
     * 新增房间信息
     * 
     * @param cmRoomInfo 房间信息
     * @return 结果
     */
    @Override
    public int insertCmRoomInfo(CmRoomInfo cmRoomInfo)
    {
        cmRoomInfo.setCreateTime(DateUtils.getTime());
        Date date = DateUtils.dateTime(DateUtils.YYYY_MM_DD, cmRoomInfo.getOperateDate());
        if (date.before(new Date())){
            cmRoomInfo.setOperateStatus("1");
        }else {
            cmRoomInfo.setOperateStatus("2");
        }
        return cmRoomInfoMapper.insertCmRoomInfo(cmRoomInfo);
    }

    /**
     * 修改房间信息
     * 
     * @param cmRoomInfo 房间信息
     * @return 结果
     */
    @Override
    public int updateCmRoomInfo(CmRoomInfo cmRoomInfo)
    {
        cmRoomInfo.setUpdateTime(DateUtils.getTime());
        return cmRoomInfoMapper.updateCmRoomInfo(cmRoomInfo);
    }

    /**
     * 批量删除房间信息
     * 
     * @param ids 需要删除的房间信息主键
     * @return 结果
     */
    @Override
    public int deleteCmRoomInfoByIds(Long[] ids)
    {
        return cmRoomInfoMapper.deleteCmRoomInfoByIds(ids);
    }

    /**
     * 删除房间信息信息
     * 
     * @param id 房间信息主键
     * @return 结果
     */
    @Override
    public int deleteCmRoomInfoById(Long id)
    {
        return cmRoomInfoMapper.deleteCmRoomInfoById(id);
    }
}
